-
Notifications
You must be signed in to change notification settings - Fork 92
Add AsQobject trait #1262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add AsQobject trait #1262
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1262 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 75 75
Lines 12764 12784 +20
=========================================
+ Hits 12764 12784 +20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
913c91b
to
3f749ed
Compare
9ed7e49
to
c3061e8
Compare
@BenFordTytherington Didn't we at some point discuss just directly implementing QObjectExt for anything that is
That way we don't need another trait 🤔 We should then however make sure to move all methods from QObject into QObjectExt (even dump_object_info) |
Just attempted to implement it for all these upcasting types for a bit, and the main problem is that now QObject upcasts to QObject, so we get a conflicting impl. I think this is initially why we went for a separate trait, and a blanket impl there, since |
Why would we get a conflicting impl? |
03f6cb8
to
b010ed1
Compare
b010ed1
to
59c885a
Compare
@@ -64,12 +67,10 @@ pub trait QObjectExt { | |||
fn object_name(&self) -> QString; | |||
|
|||
/// Returns a mutable pointer to the parent object. | |||
fn parent(&self) -> *mut Self; | |||
fn parent(&self) -> *mut QObjectExternal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if this should be a QObject not external? As i might want to ask for the parent and then downcast from QObject* to a T* ? Guess we'd need to cast the QObjectExternal -> QObject in the parent method?
Or do we think that we do not need that and QObjectExternal is fine? 🤔
59c885a
to
7e77d34
Compare
@@ -35,6 +35,9 @@ pub mod ffi { | |||
|
|||
#[rust_name = "set_parent"] | |||
pub unsafe fn setParent(self: Pin<&mut Self>, parent: *mut QObjectExternal); | |||
|
|||
#[rust_name = "dump_object_info"] | |||
fn dumpObjectInfo(&self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be pub
otherwise things will complain about it being unused :-)
- All objects which upcast to QObject now have QObjectExt implemented - Via transitive casting and using the QObjectExt trait, any descendent of QObject can access its methods
7e77d34
to
ca22759
Compare
A trait which will wrap the QObjectExt methods for types which upcast to QObject. When used in conjunction with #1252 and #1226, this will allow any type that inherits from QObject - even if this is through many levels of inheritance - to have an
as_qobject
method, and if the trait is imported, expose the methods of QObject directly on that child class. Closes #562.